<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateTableAddMybankRefundTableWithhold extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('mybank_order_withhold_refund_record', function (Blueprint $table) {
            $table->id();
            $table->string('participantType', 128)->default('')
                  ->comment('退款付方类型，即原支付单收方商户(MERCHANT)、 平台(PLATFORM)');
            $table->string('participantId', 128)->default('')
                  ->comment('退款付方id，即原支付单收方 如果是商户，则填入merchantId,如果是平台，则填入isvOrgId');
            $table->string('relateOrderNo', 64)->default('')->comment('关联网商订单号');
            $table->string('relateTransNo', 64)->default('')
                  ->comment('关联网商支付流水号， 支付流水号 1）如果大额来账创建订单类型为单次订单，可不填 2）如果大额来账创建订单类型为订单累计，则必填');
            $table->string('outOrderNo', 128)->default('')->comment('OutOrderNo');
            $table->string('outRefundNo', 64)->default('')
                  ->comment('退款外部交易号。由合作方生成，同笔退款交易，交易状态未明需要重试时，使用同一个交易号.');
            $table->string('refundOrderNo', 64)->default('')
                  ->comment('退款网商订单号');

            $table->unsignedInteger('refundAmount',)->default(0)
                  ->comment('订单退款金额。向渠道退款金额');
            $table->unsignedInteger('freezeAmount')->default(0)->comment('冻结部分出金（分）');
            $table->unsignedInteger('availableAmount')->default(0)->comment('可用部分金额（分）');

            $table->string('currency', 3)->default('')->comment('币种');
            $table->string('refundReason', 256)->default('')->comment('退款原因');
            $table->string('memo', 128)->default('')->comment('备注（可填写订单描述信息）');
            $table->string('extInfo', 512)->default('')->comment('扩展信息');
            $table->unsignedInteger('status')->default(0)->comment('状态 1 已提交申请 2 成功 3 失败');
            $table->unsignedInteger('submitDateTime')->default(0)->comment('交易提交时间');
            $table->unsignedInteger('refundFinishDate')->default(0)->comment('退款完结时间');
            $table->string('errorCode', 32)->default('')->comment('FAIL 错误码');
            $table->string('errorDesc', 500)->default('')->comment('错误描述');


//            $table->unsignedBigInteger('outTradeNo')->default(0)->comment('代扣业务订单号(外部流水号)');
//            $table->string('batchNo', 32)->default('')->comment('批处理号');
//            $table->string('orderNo', 128)->default('')->comment('网商订单号');
//            $table->string('operateNo', 128)->default('')->comment('当前网商操作单号');
//            $table->string('scene', 32)->default('')
//                  ->comment('业务场景：品牌协议代扣场景：PROTOCOL_WITHHOLD品牌协议代扣支持冻结场景：PROTOCOL_WITHHOLD_SUPPORT_FREEZE');

//            $table->string('payerId', 64)->default('')->comment('付款方商户号');
//            $table->string('payerType', 16)->default('')->comment('付款方类型：MERCHANT');
//            $table->string('payeeId', 64)->default('')->comment('收款方ID');
//            $table->string('payeeType', 16)->default('')->comment('收款方类型 MERCHANT/PLATFORM');
//


            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('updatedAt')->default(0)->comment('更新时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('更新人');
            $table->tinyInteger("isDeleted")->default(0)->comment("是否删除,0:未删除,1:已删除");

            $table->unique('outOrderNo', 'unique_idx_outOrderNo');

            $table->comment = '网商协议代扣_退款_记录表';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('mybank_order_withhold_refund_record');
    }
}
